///@author:create by BZY
///Date: 2021/9/27 16:24
///Description: 与android 和IOS 交互的方法,为了减少耦合方法统一放到此处
import 'dart:convert';

import 'package:get/get.dart';
import 'package:manager/services/plugin_service.dart';

import '../models/plugin_callback.dart';

///应用市场
void toAppDetail() {
  Get.find<PluginService>().toAppDetail();
}

///跳转到 appStore,目前仅限ios使用
void intentAppStore() {
  Get.find<PluginService>().intentAppStore();
}

void intentSystemBrowser(String url) {
  Get.find<PluginService>().intentSystemBrowser(url);
}

///清除缓存
Future<PluginCallBack<dynamic>> clearCache() async {
  return PluginCallBack<dynamic>.fromJson(
      formatJson(await Get.find<PluginService>().clearCache()));
}

///清除cookie
Future<PluginCallBack<dynamic>> clearCookie() async {
  return PluginCallBack<dynamic>.fromJson(
      formatJson(await Get.find<PluginService>().clearCookie()));
}

///从android 和ios接收的json数据格式不对,这里需要进行转换
dynamic formatJson(jsonSrc) {
  return json.decode(json.encode(jsonSrc));
}
